package com.heima.jopo.servlet;

import com.heima.jopo.obj.UserInfo;
import com.heima.jopo.web.SeleList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/verify")
public class VerifyServlet extends HttpServlet {
    /**
     * 通过AJax 异步查询手机号是否存在
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("---------------------------------");

        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");
        String ipone = request.getParameter("zh");
        System.out.println("ipone" + ipone);
        HttpSession session = request.getSession();

        SeleList seleList = new SeleList();
        PrintWriter writer = response.getWriter();

        List<UserInfo> userInfos = seleList.selectUserinfo();


        for (UserInfo userInfo : userInfos) {
            System.out.println("lsit" + userInfo.getPhone());
            if (userInfo.getPhone().equals(ipone)) {
                writer.println("账号已经存在");
                return;
            }
        }
        writer.println("账号允许");
        return;
    }
}
